package com.zr.utils.page;

import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName PageUtil
 * @Description TODO
 * @Author 分页工具类
 * @Date 2019/11/7 18:57
 */
@Component
public class PageUtil<T> {
    
    /**
    *当前页
    */
    private Integer pageIndex;

    /**
    *每页大小
    */
    private Integer pageSize;

    /**
    *总页数
    */
    private Integer totalPage;

    /**
    *总条数
    */
    private Integer totalNumber;
    /**
    *每页的第一条记录
    */
    private Integer index;
    /**
     *每页的数据
     */
    private List<T> dataList;

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
        setTotalPage();
        setIndex();
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    private void setTotalPage() {
        this.totalPage = (this.totalNumber%this.pageSize==0)?(this.totalNumber/this.pageSize):(this.totalNumber/this.pageSize+1);

    }

    public Integer getTotalNumber() {
        return totalNumber;
    }

    public void setTotalNumber(Integer totalNumber) {
        this.totalNumber = totalNumber;
    }

    public Integer getIndex() {
        return index;
    }

    private void setIndex() {
        this.index = this.pageSize*(this.getPageIndex()-1);
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    @Override
    public String toString() {
        return "PageUtil{" +
                "pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                ", totalPage=" + totalPage +
                ", totalNumber=" + totalNumber +
                ", index=" + index +
                ", dataList=" + dataList +
                '}';
    }
}
